Skip to content

fix: repair failing tests and type errors across api and shared packages - #107

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2443-1785093680
Open

fix: repair failing tests and type errors across api and shared packages#107
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2443-1785093680

Conversation

@stooit

@stooit stooit commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all failing tests (now 22 pass / 0 fail) and eliminates all type errors (tsc --noEmit clean) across the api and shared packages. Each fix targets the root cause rather than papering over the symptom.

Root causes fixed

File Fix
packages/shared/src/utils/pagination.ts Implemented the paginate stub per the test contract (data slice, total, totalPages, page, pageSize; empty array → totalPages 0; 1-indexed pages).
packages/shared/src/types.ts Renamed User.userNameusername to match the spelling used by tests and route handlers.
packages/api/src/routes/users.ts Added the missing badRequest import from ../lib/errors (was a runtime ReferenceError).
packages/api/src/middleware/auth.ts Fixed a case-sensitivity bug: the public-methods allowlist used lowercase "post" but c.req.method is uppercase, so POST /users was wrongly rejected. Now ["GET", "POST"].
tsconfig.json Added "types": ["bun-types"] (already installed) to resolve Cannot find module 'bun:test' and Cannot find name 'process'.

Verification

  • bun test → 22 pass / 0 fail
  • bunx tsc --noEmit → 0 errors

Assumptions & scope

  • No test files modified, no dependencies added, no package.json changes — per task constraints.
  • Field-name mismatch resolved toward username (lowercase) because tests and existing route code already use that spelling; the shared type was the sole outlier.
  • Pagination follows the test contract exactly: an empty array yields totalPages: 0 (no clamping to 1). Input guards for out-of-contract values (negative page, size 0/NaN) were intentionally not added — no route currently calls paginate, the tests don't exercise those inputs, and the constraint was to fix only what tests require. Noted here as a latent hardening opportunity for whoever first wires ?page=/?size= into a route.

Pre-existing, out-of-scope (untouched, noted for awareness)

  • auth.ts uses a hardcoded token fallback and a non-constant-time comparison — acceptable in this test corpus, not introduced or modified by this change.

- implement paginate stub in shared/utils per test contract
- align User type field username (was userName) with tests and routes
- add missing badRequest import in users route
- fix auth middleware method-casing allowlist so POST /users is public
- add bun-types to tsconfig types to resolve bun:test and process type errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant